package thread;

import java.util.LinkedList;

public class RequestQueue {
    private final LinkedList queue = new LinkedList();

    public synchronized Request getRequest() {
        while (queue.size() <= 0) {
            try {
                //当条件不满足是,进入 wait set
                wait();
                //当被唤醒的时候，只有拿到锁定的server thread才能执行下一个请求
            } catch (InterruptedException e) {
            }
        }
        return (Request) queue.removeFirst();
    }

    public synchronized void putRequest(Request request) {
        queue.addLast(request);
        //当条件满足的时候，唤醒所有的server thread
        notifyAll();
    }
}